package com.itbaima.csmall.stock.webapi.quartz.kafka;

import com.google.gson.Gson;
import com.itbaima.csmall.commons.pojo.stock.entity.Stock;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.math.RandomUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
// import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.kafka.core.KafkaTemplate;


/**
 * <p>Quartz任务</p>
 *
 * @author Chen
 * @since 2023/3/3 16:13:13
 */
@Slf4j
public class KafkaJob implements Job {

    // @Autowired
    // private KafkaTemplate<String, String> kafkaTemplate;
    public static final String TOPIC_STOCK_KEY = "myStock";
    static int i = 1;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        Stock stock = new Stock();
        stock.setId(i++);
        stock.setCommodityCode("PC100");
        stock.setReduceCount(1 + RandomUtils.nextInt(10));
        Gson gson = new Gson();
        String json = gson.toJson(stock);
        log.info("即将发送消息：{}", json);
        // kafkaTemplate.send(TOPIC_STOCK_KEY, json);
    }

}
